package 力扣日常刷题.木23一月.第13天313;


/**
 * @author 帅小伙
 * @date 2022/3/13
 * @description
 */
public class Demo62 {

    public static void main(String[] args) {
        System.out.println(maximumTop(new int[]{ 2, 2, 0 , 4, 0,6}, 4));
    }

    public static int maximumTop(int[] nums, int k) {
        if(nums.length == 1 && k %2 == 1) return -1;
        if(nums.length == 1) return nums[0];
        int ans = Integer.MIN_VALUE;
        for (int i = 0; i < nums.length; i++) {
            if((k >= i) &&((k - i) % 2 == 0 || (k - i - 2) >0)) ans = Math.max(ans,nums[i]);
        }
        return ans;
    }
}
